🎖️GitЯра🎖️
Node / meshtastic / Meshtastic-Android / files / core / ui / src / androidMain / kotlin / org / meshtastic / core / ui / util / PermissionRequestTracker.kt
Displaying Raw • Download
core/ui/src/androidMain/kotlin/org/meshtastic/core/ui/util/PermissionRequestTracker.kt 01cd54907d62cd90913d3d071b6bc240cae365ef (01cd5490) Text, 2.26 KB
T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.ui.util
Tff7b72import T7ee787android.content.Context
T8b949e/**
* Persists, per Android permission string, whether the app has ever completed a runtime request for it.
*
* This flag is the disambiguator required by [computePermissionStatus]: `shouldShowRequestPermissionRationale` returns
* `false` both before the first prompt and after a permanent denial, so a persisted "has been requested" marker is the
* only way to tell the two apart.
*
* Deliberately backed by [android.content.SharedPreferences] rather than DataStore: the flag is read synchronously
* inside composition (in the same pass as the rationale check) and written synchronously from a permission-result
* callback. DataStore's asynchronous `Flow` model would introduce a read-after-write race on exactly the transition the
* permission state machine hinges on.
*/
Tff7b72internal Tff7b72class T56d364PermissionRequestTrackerTb4b4b4(Te6edf3contextTb4b4b4: Te6edf3ContextTb4b4b4) Tb4b4b4{
Tff7b72private Tff7b72val Te6edf3prefs Tff7b72= Te6edf3contextTb4b4b4.Te6edf3applicationContextTb4b4b4.Te6edf3getSharedPreferencesTb4b4b4(Te6edf3PREFS_NAMETb4b4b4, Te6edf3ContextTb4b4b4.Te6edf3MODE_PRIVATETb4b4b4)
Tff7b72fun Td2a8ffhasRequestedTb4b4b4(Te6edf3permissionTb4b4b4: Tffa657StringTb4b4b4)Tb4b4b4: Tffa657Boolean Tff7b72= Te6edf3prefsTb4b4b4.Te6edf3getBooleanTb4b4b4(Te6edf3permissionTb4b4b4, Tff7b72falseTb4b4b4)
T8b949e/**
* Marks [permission] as having completed a request. MUST be called from the launcher's result callback (after the
* OS has adjudicated the request), never when `launch()` is merely invoked — see [computePermissionStatus].
*/
Tff7b72fun Td2a8ffmarkRequestedTb4b4b4(Te6edf3permissionTb4b4b4: Tffa657StringTb4b4b4) Tb4b4b4{
Te6edf3prefsTb4b4b4.Te6edf3editTb4b4b4(Tb4b4b4)Tb4b4b4.Te6edf3putBooleanTb4b4b4(Te6edf3permissionTb4b4b4, Tff7b72trueTb4b4b4)Tb4b4b4.Te6edf3applyTb4b4b4(Tb4b4b4)
Tb4b4b4}
Tff7b72private Tff7b72companion Tff7b72object Tb4b4b4{
Tff7b72const Tff7b72val Te6edf3PREFS_NAME Tff7b72= Ta5d6ff"Ta5d6ffmeshtastic_permissionsTa5d6ff"
Tb4b4b4}
Tb4b4b4}
Served by rngit 1.5.0 - Generated in 0.11s